
from pages.base_page import BasePage
from selenium.webdriver.common.by import By

class FinanceAddGatheringPage(BasePage):
    #当前url
    url = "/crm/index.php?m=finance&a=add&t=receivables"
    #定位器
    #添加应收款用户名定位器
    finance_add_gathering_name_locator = (By.NAME, "name")
    #添加应收款合同定位器
    finance_add_gathering_contract_locator = (By.NAME, "contract_name")
    #添加应收款合同列表定位
    table1_locator = (By.ID, "data")
    #添加应收款合同列表的tr标签定位
    tr_locator = (By.TAG_NAME, "tr")
    # 添加应收款合同列表的td标签定位
    td_locator = (By.TAG_NAME, "td")
    # 添加应收款合同列表勾选定位器
    choice1_locator = (By.CSS_SELECTOR, "#data > tr:nth-child(1) > td:nth-child(1) > input[type=radio]")
    #添加应收款合同的确认定位器
    ok1_locator = (By.CSS_SELECTOR,"body > div:nth-child(9) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span")
    #添加应收款客户定位器
    finance_add_gathering_customer_locator = (By.NAME, "customer")
    #添加因收款客户列表定位器
    table2_locator = (By.CSS_SELECTOR, "#datas")
    #添加应收款客户列表选择定位器
    choice2_locator = (By.CSS_SELECTOR, "#datas > tr:nth-child(1) > td:nth-child(1) > input[type=radio]:nth-child(1)")
    #添加应收款客户列表确认定位器
    ok2_locator = (By.XPATH, "/html/body/div[7]/div[3]/div/button[1]")
    #添加应收款数额定位器
    payment_money_locator = (By.ID, "price")
    #添加应收款的创建收款单勾选定位器
    choice3_locator = (By.ID, "check_add_order")
    #添加应收款的创建收款单金额定位器
    order_money_locator = (By.ID, "order_money")
    #添加应收款的创建收款单支付时间定位器
    pay_time1_locator = (By.CSS_SELECTOR, "#add_order > tbody > tr:nth-child(3) > td:nth-child(2) > input[type=text]")
    #添加应收款的创建收款单的状态定位器
    order_status_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]/table/tbody/tr[4]/td[2]/input[2]")
    #添加应收款的收款时间定位器
    pay_time2_locator = (By.CSS_SELECTOR, "#pay_time")

    save_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)")
    #添加应收款成功弹窗定位器
    add_gathering_alert_locator = (By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")

    # 操作方法

    def order_name_input(self, finance_add_gathering_name):
        self.find_element(self.finance_add_gathering_name_locator).send_keys(finance_add_gathering_name)

    def order_contract_click(self):
        self.find_element(self.finance_add_gathering_contract_locator).click()

    def order_contract_table_choice(self):
        self.find_element(self.choice1_locator).click()


    def order_contract_ok_click(self):
        self.find_element(self.ok1_locator).click()

    def order_customer_click(self):
        self.find_element(self.finance_add_gathering_customer_locator).click()

    def order_customer_table_choice(self):
        self.find_element(self.choice2_locator).click()

    def order_customer_ok_click(self):
        self.find_element(self.ok2_locator).click()

    def order_payment_money_input(self,payment_money):
        self.find_element(self.payment_money_locator).clear()
        self.find_element(self.payment_money_locator).send_keys(payment_money)

    def order_add_gathering_choice_click(self):
        self.find_element(self.choice3_locator).click()

    def order_add_gathering_money_input(self,payment_money):
        self.find_element(self.order_money_locator).send_keys(payment_money)

    def order_add_gathering_time_input(self,pay_time):
        self.find_element(self.pay_time1_locator).clear()
        self.find_element(self.pay_time1_locator).send_keys(pay_time)

    def order_add_gathering_status_click(self):
        self.find_element(self.order_status_locator).click()

    def order_pay_time_input(self, pay_time):
        self.find_element(self.pay_time2_locator).send_keys(pay_time)

    def order_save_click(self):
        self.find_element(self.save_locator).click()

    def add_gathering_alert(self):
        return self.find_element(self.add_gathering_alert_locator).text


